﻿@model Telecom.Data.DM_THIETBI

@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequestAdUpTB"
    };
}

<script type="text/javascript">

    function opBeginProcess_loading_window_submit() {
        $("#ContentwindowFunction").mask("Dữ liệu đang xử lý");
    }

    function completedAjaxRequestAdUpTB(obj) {

            var returnObj = eval('(' + obj.responseText + ')');

            if (returnObj.Status == "success") {


                var nodeTreeGirdDV = $('#TreeGird_MVT_LOAITB').treegrid('getSelected');

                if (nodeTreeGirdDV == null) {

                    $('#thietbi_TableContainer').jtable('load', { idObject: "0" , type: "all" });

                }
                else {

                    $('#thietbi_TableContainer').jtable('load', { idObject: nodeTreeGirdDV.id, type: nodeTreeGirdDV.type });

                }

                close_window_elements('window_addupdate_thietbi');


            } else {

                $("#ContentwindowFunction").unmask();
                confirmOptionNormal(returnObj.Message);
            }

            return false;

        }

        $(document).ready(function () {

            $("#loaiTBAdUpTB").combobox({
                valueField: "MA",
                textField: "TEN",
                onSelect: function (row) {
                    $("#LOAITB_AdUpTb").val(row.MA);
                }
            });

            $("#mangVtAdUpTB").combobox({
                url: _nameSubDomain + "/Dm_ThietBi/ListMangVT",
                valueField: "MA",
                textField: "TEN",
                onSelect: function (row) {
                    loadDatainToLoaiTB(row.MA);
                },
                onLoadSuccess: function (row, index) {
                    if($("#MangVTHidenID").val() != "")
                    {
                        loadDatainToLoaiTB($("#MangVTHidenID").val());
                    }
                }
            });

            $("#HangSXAdUpTB").combobox({
                url: _nameSubDomain + "/Dm_ThietBi/ListHangSX",
                valueField: "MA",
                textField: "TEN",
                onSelect: function (row) {
                    $("#HANGSX_AdUpTb").val(row.MA);
                }
            
            });

            var buttonlogo_filebccv = $("#file-upload-add-tb")[0];
            var uploader_bccv = new qq.FileUploader({
                element: buttonlogo_filebccv,
                allowedExtensions: [],
                sizeLimit: 2147483647, // max size
                action: _nameSubDomain + '/Home/UploadFile',
                multiple: false,
                onSubmit: function (file, extension) {
                    //$('div.preview').addClass('loading');
                },
                onComplete: function (id, fileName, responseJSON) {

                    $(".load_file_upload_add_tb").html("");

                    $("#HinhAnh_AdUpTB").val(responseJSON._path);

                    var tpl = $('<p class="working" style="position:relative"><img width="50px" src=' + _nameSubDomain + "/Content/fileUpload/" + responseJSON._path + ' /><span class="spanremove_fileuploadbc span_remove_file" data-filename="' + responseJSON._path + '"></span></p>');


                    // Add the HTML to the UL element
                    $(".load_file_upload_add_tb").html(tpl);

                    // Listen for clicks on the cancel icon
                    $('span.spanremove_fileuploadbc').click(function () {


                        var filename = ($(this).attr("data-filename"));
                        var _this = $(this);

                        $.ajax({ url: _nameSubDomain + "/Home/DeleFile?file=" + filename, async: false }).done(function (data) {

                            _this.parent('.working').fadeOut(function () {
                                $(this).remove();
                            });

                            $("#HinhAnh_AdUpTB").val("");

                        });

                    });

                }
            });

        });

        function loadDatainToLoaiTB(ma) {
            $("#loaiTBAdUpTB").combobox({ url: _nameSubDomain + "/Dm_ThietBi/ListLoaiTb?ma=" + ma });
        }

</script>

@using (Ajax.BeginForm("AdUpTB", "Dm_ThietBi", null, ajaxOpts, new { enctype = "multipart/form-data" }))
{
    @Html.HiddenFor(model => model.ID)
    @Html.HiddenFor(model => model.HINHANH, new { id = "HinhAnh_AdUpTB" })
    @Html.HiddenFor(model => model.LOAITB, new { id = "LOAITB_AdUpTb" })
    @Html.HiddenFor(model => model.HANGSX, new { id = "HANGSX_AdUpTb" })
    <input type="hidden" id="MangVTHidenID" value="@ViewBag.MVTADDTB" />
    
    <div id="ContentwindowFunction" class="ContentwindowFunction">
       <table class="tableContentWindowFunction">
           <tr>
                <td>
                   Mạng VT
                </td>
               <td>
                    <input class="easyui-combobox" value="@ViewBag.MVTADDTB" style="width:450px; height:27px" id="mangVtAdUpTB" name="mangVtAdUpTB">
               </td>
           </tr>
           <tr>
                <td>
                    Loại TB
                </td>
               <td>
                   <input class="easyui-combobox" value="@Model.LOAITB" style="width:450px;height:27px" id="loaiTBAdUpTB" name="loaiTBAdUpTB">
               </td>
           </tr>
           <tr>
                <td>
                    Mã TB
                </td>
               <td>
                   @Html.TextBoxFor(model => model.MA, new { @class = "input_table_function maTable"})
               </td>
           </tr>
           <tr>
                <td>
                    Tên TB
                </td>
               <td>
                   @Html.TextBoxFor(model => model.TEN, new { @class = "input_table_function"})
               </td>
           </tr>
           <tr>
                <td>
                    Hãng SX
                </td>
               <td>
                   <input class="easyui-combobox" value="@Model.HANGSX" style="width:450px; height:27px" id="HangSXAdUpTB" name="HangSXAdUpTB">
               </td>
           </tr>
           <tr>
                <td>
                    Ghi Chú
                </td>
               <td>
                   @Html.TextAreaFor(model => model.GHICHU, new { @class = "input_table_function"})
               </td>
           </tr>
           <tr>
                <td>
                    Hình Ảnh
                </td>
               <td style="position:relative">
                   <div id="file-upload-add-tb" style="">
                   </div>
                    <div class="load_file_upload_add_tb" style="position:absolute; left:150px;top:9px; z-index:999">

                    </div>
               </td>
           </tr>
       </table>
        <div style="height:30px"></div>
        <div class="footer_submit" style="margin-top: 10px; text-align: center">
            <button type="submit" onclick="return opBeginProcess_loading_window_submit(); ">
                <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">Cập nhật thiết bị</span><span class="l-btn-icon icon-add">&nbsp;</span></span>    
            </button>
            <button type="button" onclick="return close_window_elements('window_addupdate_thietbi');" >
                <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">Hủy bỏ</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></button>
        </div>
    </div>
    

}